home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-05-01 | 80.4 KB | 3,026 lines | [TEXT/MPS ] |
- // UView.cp
- // Copyright © 1987-1991 by Apple Computer Inc. All rights reserved.
-
- #ifndef __STDIO__
- #include <StdIo.h>
- #endif
-
- #ifndef __UGEOMETRY__
- #include <UGeometry.h>
- #endif
-
- #ifndef __ULIST__
- #include <UList.h>
- #endif
-
- #ifndef __UEVENT__
- #include <UEvent.h>
- #endif
-
- #ifndef __UCOMMAND__
- #include <UCommand.h>
- #endif
-
- #ifndef __EDITIONS__
- #include <Editions.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __UAPPLICATION__
- #include <UApplication.h>
- #endif
-
- #ifndef __UVIEWBEHAVIOR__
- #include <UViewBehavior.h>
- #endif
-
- #ifndef __UDOCUMENT__
- #include <UDocument.h>
- #endif
-
- #ifndef __SCRAP__
- #include <Scrap.h>
- #endif
-
- #ifndef __UCLIPBOARDMGR__
- #include <UClipboardMgr.h>
- #endif
-
- #ifndef __UPRINTHANDLER__
- #include <UPrintHandler.h>
- #endif
-
- #ifndef __UWINDOW__
- #include <UWindow.h>
- #endif
-
- #ifndef __USCROLLER__
- #include <UScroller.h>
- #endif
-
- #ifndef __UFAILURE__
- #include <UFailure.h>
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include <UMacAppUtilities.h>
- #endif
-
- #ifndef __UPATCH__
- #include <UPatch.h>
- #endif
-
- #ifndef __UMEMORY__
- #include <UMemory.h>
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include <UMacAppGlobals.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __UVIEW__
- #include <UView.h>
- #endif
-
- // global declarations for globals defined in interface
- TView* gFocusedView;
- Boolean gDrawingPictScrap;
- TView* gDrawingPictScrapView;
- Boolean gPrinting;
- TPrintHandler* gCurrPrintHandler;
- TPrintHandler* gNullPrintHandler;
- VPoint gPageOffset;
- TPrintHandler* gPrintHandler;
- IDType gWResSignature;
- Str255 gWResType;
-
- const unsigned char kFrame = adnLineTop | adnLineLeft | adnLineBottom | adnLineRight;
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- CSubViewIterator::CSubViewIterator(TView* itsView,
- ArrayIndex itsLowBound,
- ArrayIndex itsHighBound,
- Boolean itsForward) :
- CObjectIterator(itsView ? itsView->fSubViews : NULL, itsLowBound, itsHighBound, itsForward)
- {
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- CSubViewIterator::CSubViewIterator(TView* itsView,
- Boolean itsForward) :
- CObjectIterator(itsView ? itsView->fSubViews : NULL, itsForward)
- {
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- CSubViewIterator::CSubViewIterator(TView* itsView) :
- CObjectIterator(itsView ? itsView->fSubViews : NULL)
- {
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- TView* CSubViewIterator::CurrentSubView(void)
- {
- return (TView*)this->CurrentObject();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- TView* CSubViewIterator::FirstSubView(void)
- {
- return (TView*)this->FirstObject();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- TView* CSubViewIterator::NextSubView(void)
- {
- return (TView*)this->NextObject();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAGlobalsRes
-
- pascal void VisibleRect(Rect& r)
- {
- #if qDebug
- UseTempRgn("VisibleRect");
- #endif
-
- RectRgn(gTempRgn, r);
- SectRgn(gTempRgn, qd.thePort->visRgn, gTempRgn);
- r = (*gTempRgn)->rgnBBox;
- #if qDebug
- DoneWithTempRgn();
- #endif
-
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAGlobalsRes
-
- pascal void DrawableRect(Rect& r)
- {
- VisibleRect(r);
- #if qDebug
- UseTempRgn("VisibleRect");
- #endif
-
- RectRgn(gTempRgn, r);
- SectRgn(gTempRgn, qd.thePort->clipRgn, gTempRgn);
- r = (*gTempRgn)->rgnBBox;
- #if qDebug
- DoneWithTempRgn();
- #endif
-
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAGlobalsRes
-
- pascal void PtAndRgn(Point aPoint,
- RgnHandle aRegion)
- {
- //!!! Error checking?
- #if qDebug
- UseTempRgn("PtAndRgn");
- #endif
-
- SetRectRgn(gTempRgn, aPoint.h, aPoint.v, aPoint.h + 1, aPoint.v + 1);
- UnionRgn(gTempRgn, aRegion, aRegion);
-
- #if qDebug
- DoneWithTempRgn();
- #endif
-
- }
-
- //--------------------------------------------------------------------------------
- #pragma segment MAGlobalsRes
-
- pascal void VRectAndRgn(const VRect& theVRect,
- RgnHandle theRgn)
- {
- #if qDebug
- UseTempRgn("VRectAndRgn");
- #endif
-
- RectRgn(gTempRgn, theVRect);
- UnionRgn(gTempRgn, theRgn, theRgn);
-
- #if qDebug
- DoneWithTempRgn();
- #endif
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal ViewRsrcHandle NewViewRsrc(Ptr& p)
- {
- ViewRsrcHandle aHandle = (ViewRsrcHandle)(NewPermHandle(kViewRsrcExpandAmt));
- LockHandleHigh((Handle)aHandle);
-
- (*aHandle)->numViews = 0;
- p = (Ptr) & ((*aHandle)->theViews);
-
- return aHandle;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal void OffsetPtr(Ptr& p,
- long offset)
- {
- p += offset;
- if (((long)p) & 1)
- ++p;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal void OffsetPtrWStr(Ptr& p,
- long offset)
- {
- OffsetPtr(p, offset - 255 + (*(StringPtr)(p + offset - 256)).Length());
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void DoneViewRsrc(Handle viewRsrc,
- long lastPtr)
- {
- HUnlock(viewRsrc);
- SetPermHandleSize(viewRsrc, StripLong((void*)lastPtr) - StripLong((*viewRsrc)));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Ptr ExpandPtr(Handle viewRsrc,
- Ptr& p,
- long offset)
- {
- Ptr returnValue;
-
- Size rsrcSize = GetHandleSize(viewRsrc);
- long rsrcBase = StripLong((*viewRsrc));
- long currentPtr = StripLong(p);
-
- if (offset & 1)
- ++offset;
- long desiredEnd = currentPtr + offset + sizeof(short);
-
- if (desiredEnd >= rsrcBase + rsrcSize)
- {
- // This appropriation logic might need some re-examination. If the size of the added
- // template is larger than the minimum amount, then simply the size is added. If
- // the handle is already near to being full, this won't help for the next allocation.
- // Maybe it should use a hystersis?…
- long oldOffset = currentPtr - rsrcBase;
- HUnlock(viewRsrc);
- SetHandleSize(viewRsrc, rsrcSize + Max(kViewRsrcExpandAmt, offset));
- FailMemError();
- LockHandleHigh(viewRsrc);
- p = (Ptr)((*viewRsrc)) + oldOffset;
- }
-
- returnValue = p;
- OffsetPtr(p, offset);
- return (returnValue);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Ptr ExpandPtrWStr(Handle viewRsrc,
- Ptr& p,
- long offset,
- const long len)
- {
- return ExpandPtr(viewRsrc, p, offset - 255 + len);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Boolean IsPtVisible(Point pt)
- {
- return PtInRgn(pt, qd.thePort->visRgn);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Boolean IsPtDrawable(Point pt)
- {
- return IsPtVisible(pt) && PtInRgn(pt, qd.thePort->clipRgn);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Boolean IsRectVisible(const Rect& r)
- {
- return RectInRgn(r, qd.thePort->visRgn);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Boolean IsRectDrawable(const Rect& r)
- {
- return IsRectVisible(r) && RectInRgn(r, qd.thePort->clipRgn);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void GetFocus(FocusRec& theFocusRec)
- {
- GetViewPortInfo(theFocusRec.itsViewPortInfo);
-
- theFocusRec.focusedView = gFocusedView;
- theFocusRec.printing = gPrinting;
- theFocusRec.drawingPictScrap = gDrawingPictScrap;
- theFocusRec.drawingPictScrapView = gDrawingPictScrapView;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void SetFocus(const FocusRec& theFocusRec)
- {
- gFocusedView = theFocusRec.focusedView;
- gPrinting = theFocusRec.printing;
- gDrawingPictScrap = theFocusRec.drawingPictScrap;
- gDrawingPictScrapView = theFocusRec.drawingPictScrapView;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void GetViewPortInfo(ViewPortInfo& theViewPortInfo)
- {
- GetPort(theViewPortInfo.port);
- GetClip(theViewPortInfo.clip);
- theViewPortInfo.org = theViewPortInfo.port->portRect[topLeft];
- theViewPortInfo.isValid = TRUE;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void SetViewPortInfo(const ViewPortInfo& theViewPortInfo)
- {
- if (qd.thePort != theViewPortInfo.port) // be nice to accelerator cards
- SetPort(theViewPortInfo.port);
- if (qd.thePort->portRect[topLeft] != theViewPortInfo.org)
- SetOrigin(theViewPortInfo.org.h, theViewPortInfo.org.v);
- SetClip(theViewPortInfo.clip);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADebug
-
- pascal void WriteFocus(void)
- {
- WrLblVPt(" fViewToQDOffset", gFocusedView->fViewToQDOffset);
- fprintf(stderr, "\n");
- WrLblRect(" portRect", qd.thePort->portRect);
- fprintf(stderr, "\n");
- WrLblRect(" visRgn", (*(qd.thePort->visRgn))->rgnBBox);
- fprintf(stderr, "\n");
- WrLblRect(" clipRgn", (*(qd.thePort->clipRgn))->rgnBBox);
- fprintf(stderr, "\n");
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal void TView::Initialize(void) // override
- {
- inherited::Initialize();
-
- fCursorID = kNoResource;
- fHelpID = kNoResource;
- fSuperView = NULL;
- fSubViews = NULL;
- fDocument = NULL;
- fLocation = gZeroVPt;
- fSize = gZeroVPt; // ??? Should this be non-zero?
- fSizeDeterminer[hSel] = sizeVariable;
- fSizeDeterminer[vSel] = sizeVariable;
- fHLDesired = hlOff;
- fShown = TRUE;
- fPrintHandler = NULL;
- fTranslation = gZeroVPt;
- fViewToQDOffset = gZeroVPt;
- fQDOrigin = gZeroPt;
- fVisibleExtent = gZeroVRect;
- fViewAdornment = NULL;
- fHandlesCursor = TRUE;
- fLetsSubViewsHandleCursor = TRUE;
- fHandlesHelp = TRUE;
- fLetsSubViewsHandleHelp = TRUE;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal void TView::IView(TDocument* itsDocument,
- TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet)
- {
- FailInfo fi;
-
- this->IEvtHandler(itsSuperView);
-
- // fSuperView = itsSuperView; <= set in AddSubView's call to BeInSuperView (see below...)
- fDocument = itsDocument;
- fLocation = itsLocation;
- fSize = itsSize;
- fSizeDeterminer[hSel] = itsHSizeDet;
- fSizeDeterminer[vSel] = itsVSizeDet;
-
- if (fi.Try())
- {
- if (itsSuperView)
- itsSuperView->AddSubView(this);
- if (itsDocument)
- itsDocument->AddView(this);
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal void TView::IRes(TDocument* itsDocument,
- TView* itsSuperView,
- Ptr& itsParams)
- {
- const SizeDeterminer allSizeDeterminerBits = sizeSuperView | sizeRelSuperView | sizePage | sizeFillPages | sizeVariable | sizeFixed;
-
- ViewTemplate & templateData = *((ViewTemplatePtr)itsParams);
-
- // assign 3bit field from templateData to local variable and mask off unused bits to avoid
- // sign extension.
- SizeDeterminer itsHSizeDet = (SizeDeterminer)(templateData.itsHSizeDet & allSizeDeterminerBits);
- SizeDeterminer itsVSizeDet = (SizeDeterminer)(templateData.itsVSizeDet & allSizeDeterminerBits);
-
- this->IView(itsDocument, itsSuperView, templateData.itsLocation, templateData.itsSize, itsHSizeDet, itsVSizeDet);
-
- this->SetEnable(templateData.isEnabled);
-
- fShown = templateData.isShown;
- fHLDesired = hlOff; // ??? This is done in Initialize. Should it
- // be included in the resource?
- fIdentifier = templateData.thisViewID;
- OffsetPtrWStr(itsParams, sizeof(ViewTemplate));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal TObject* TView::Clone(void) // override
- {
- TView * aClonedView = (TView *)(inherited::Clone());
-
- aClonedView->fSuperView = NULL;
- aClonedView->fSubViews = NULL;
-
- if (fPrintHandler)
- aClonedView->AttachPrintHandler((TPrintHandler *)fPrintHandler->Clone());
- aClonedView->fNextHandler = NULL;
- aClonedView->fDocument = NULL;
-
- return aClonedView;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TView::WRes(ViewRsrcHandle theResource,
- Ptr& itsParams)
- {
- ViewTemplatePtr vwPtr = ViewTemplatePtr(ExpandPtrWStr((Handle)theResource, itsParams, sizeof(ViewTemplate), gWResType.Length()));
-
- if (fSuperView)
- vwPtr->itsParentID = fSuperView->fIdentifier;
- else
- vwPtr->itsParentID = kNoIdentifier;
-
- vwPtr->thisViewID = fIdentifier;
- vwPtr->itsLocation = fLocation;
- vwPtr->itsSize = fSize;
- vwPtr->itsVSizeDet = fSizeDeterminer[vSel];
- vwPtr->itsHSizeDet = fSizeDeterminer[hSel];
- vwPtr->isShown = fShown;
- vwPtr->isEnabled = fEnabled;
- vwPtr->itsSignature = gWResSignature;
- // vwPtr->itsType = gWResType;
- CopyStr255(gWResType, PRStr(vwPtr->u0.itsType));
-
- // Everybody gets this far - bump number of views in resource
- ++(*theResource)->numViews;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteRes
-
- pascal void TView::WriteRes(ViewRsrcHandle theResource,
- Ptr& itsParams)
- {
- gWResSignature = 'view';
- gWResType = "TView";
- this->WRes(theResource, itsParams);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- pascal void TView::Free(void)
- {
- // Because RemoveSubView frees the list when it goes empty we don't need to actually free
- // the list right here. When each subview gets the free message it removes itself from the
- // superview (this) and the list may get deleted. Kinda twisty, huh?
-
- CSubViewIterator iter(this);
-
- for (TView * aView = iter.FirstSubView(); iter.More(); aView = iter.NextSubView())
- aView->Free();
-
- this->InvalidateFocus();
- gApplication->InvalidateMouseRegions(); // Must re-calc cursor and help rgn.
-
- if (this == gApplication->GetTarget()) // Fixup the target chain
- gApplication->SetTarget(gApplication);
-
- if (fSuperView)
- {
- fSuperView->RemoveSubView(this);
- fSuperView = NULL;
- }
-
- fViewAdornment = (TAdornment *)(FreeIfObject(fViewAdornment));
-
- if (fDocument)
- {
- fDocument->DeleteView(this);
- fDocument = NULL;
- }
-
- inherited::Free(); // will free fPrintHandler
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAActivate
-
- pascal void TView::Activate(Boolean entering)
- {
- HLState newHL;
-
- if (entering)
- newHL = hlOn;
- else
- newHL = hlDim;
-
- if (fViewAdornment && this->IsDrawable())
- {
- VRect visRect;
-
- this->GetDrawableRect(visRect);
- fViewAdornment->DoHighlightSelection(this, visRect, fHLDesired, newHL);
- }
- fHLDesired = newHL;
-
- CSubViewIterator iter(this);
-
- for (TView * aView = iter.FirstSubView(); iter.More(); aView = iter.NextSubView())
- aView->Activate(entering);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::AddAdorner(TAdorner* anAdorner,
- AdornPriority itsPriority,
- Boolean invalidate)
- {
- fViewAdornment = this->MakeAdornment();
- fViewAdornment->AddAdorner(anAdorner, itsPriority, invalidate);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::DeleteAdorner(TAdorner* anAdorner,
- Boolean invalidate)
- {
- if (fViewAdornment)
- {
- fViewAdornment->DeleteAdorner(anAdorner, invalidate);
-
- // dispose of fViewAdornment if it only contains the default gDrawAdorner
- if ((fViewAdornment->fAdorners->GetSize() == 1) && (fViewAdornment->AdornerAt(1) == gDrawAdorner))
- {
- fViewAdornment = (TAdornment *)(FreeIfObject(fViewAdornment));
- }
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
- pascal void TView::DeleteAdornerByID(IDType itsID,
- Boolean invalidate)
- {
- if (fViewAdornment)
- {
- fViewAdornment->DeleteAdornerByID(itsID, invalidate);
-
- // dispose of fViewAdornment if it only contains the default gDrawAdorner
- if ((fViewAdornment->fAdorners->GetSize() == 1) && (fViewAdornment->AdornerAt(1) == gDrawAdorner))
- {
- fViewAdornment = (TAdornment *)(FreeIfObject(fViewAdornment));
- }
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::Dim(void)
- {
- Rect area;
-
- #if qDebug
- this->AssumeFocused();
- #endif
-
- this->GetQDExtent(area);
- PenPat(qd.gray);
- PenMode(patBic);
- PaintRect(area);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::GetAdornExtent(VRect& itsAdornExtent)
- {
- this->GetExtent(itsAdornExtent);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::Hilite(void)
- {
- Rect aRect;
-
- #if qDebug
- this->AssumeFocused();
- #endif
-
- this->GetQDExtent(aRect);
- InvertRect(aRect);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal TAdornment* TView::MakeAdornment(void)
- {
-
- if (fViewAdornment)
- return fViewAdornment;
- else
- {
- TAdornment * anAdornment = new TAdornment;
-
- anAdornment->IAdornment('????', this, Point(1, 1));
- anAdornment->AddAdorner(gDrawAdorner, kViewAdornPriority, FALSE);// default "Draw" adorner
-
- return anAdornment;
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal void TView::AddedASubView(TView* newSubView)
- {
- if (fSuperView)
- fSuperView->AddedASubView(newSubView);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal void TView::AddSubView(TView* theSubView)
- {
- if (theSubView)
- {
- // Create the subview list if necessary
- if (!fSubViews)
- {
- fSubViews = NewList();
- #if qDebug
- fSubViews->SetEltType("TView");
- #endif
-
- }
- if (qDebug && (fSubViews->GetIdentityItemNo(theSubView) != kEmptyIndex))
- ProgramBreak("in TView.AddSubView: Attempting to add the same subview twice.");
-
- fSubViews->InsertLast(theSubView);
- theSubView->BeInSuperView(this);
- this->AddedASubView(theSubView);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::AdjustSize(void)
- {
- VPoint newSize(fSize);
- this->ComputeSize(newSize);
- if (newSize != fSize)
- {
- this->Resize(newSize, kInvalidate);
- this->DoPagination();
- }
- else
- {
- CSubViewIterator iter(this);
-
- for (TView * aView = iter.FirstSubView(); iter.More(); aView = iter.NextSubView())
- aView->AdjustSize();
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADebug
-
- pascal void TView::AssumeFocused(void)
- {
- if (gAssumeFocused)
- if (!IsFocused())
- {
- Str255 aString;
- MANamePtr aStringPtr;
-
- aStringPtr = MANamePtr(&aString);
- this->GetClassName((*aStringPtr));
- fprintf(stderr, ", ClassName=%s, InspectorName=", (char*)aString);
- this->GetInspectorName(aString);
- fprintf(stderr, "%s\n", (char*)aString);
- if (gFocusedView)
- {
- fprintf(stderr, "View actually focused is:\n");
- gFocusedView->GetClassName((*aStringPtr));
- fprintf(stderr, ", ClassName=%s, InspectorName=", (char*)aString);
- gFocusedView->GetInspectorName(aString);
- fprintf(stderr, "%s\n", (char*)aString);
- }
- ProgramBreak("Failed AssumeFocused");
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::AttachPrintHandler(TPrintHandler* itsPrintHandler)
- {
- this->AddAdorner(gPrintAdorner, kLowestAdornPriority, FALSE);// adorner calls DoDrawPrintFeedback
- fPrintHandler = itsPrintHandler;
- this->AddBehavior(itsPrintHandler);
- this->DoCheckPrinter();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::BeInPort(GrafPtr itsPort)
- {
-
- if ((itsPort) && (fPrintHandler))
- this->DoCheckPrinter();
-
- CSubViewIterator iter(this);
-
- for (TView * aView = iter.FirstSubView(); iter.More(); aView = iter.NextSubView())
- aView->BeInPort(itsPort);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::BeInScroller(TScroller* itsScroller)
- {
- // convert the size to superview location. ??? SRF should we localtosuper the fsize instead?
-
- if (itsScroller)
- itsScroller->SetScrollLimits(fSize + fLocation, kDontRedraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal void TView::BeInSuperView(TView* itsSuperview)
- {
- TView * oldSuperView = fSuperView;
-
- fSuperView = itsSuperview;
- this->InvalidateFocus(); // the subview may have been focused
- this->UpdateCoordinates();
-
- if (!itsSuperview)
- {
- // Removing this view from its superview
- if (fNextHandler == oldSuperView) // If next event handler is the former superview
- fNextHandler = NULL; // take this view out of the event handler chain.
- this->BeInPort(NULL);
- }
- else
- {
- if (!fNextHandler) // If necessary,
- fNextHandler = itsSuperview; // …hook this view up to an event hander chain.
- this->BeInPort(this->GetGrafPort());
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
- pascal void TView::BeTarget(void)
- {
- this->SetTarget(this);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::CalcMinSize(VPoint& minSize)
- {
- minSize = fSize;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- // Set clipping to: (<current clipping> INTERSECT r) OFFSET-BY (hDeltaOrg, vDeltaOrg)
- pascal void TView::ClipFurtherTo(const Rect& r,
- short hDeltaOrg,
- short vDeltaOrg)
- {
- #if qDebug
- this->AssumeFocused();
- UseTempRgn("ClipFurtherTo");
- #endif
-
- RectRgn(gTempRgn, r);
- SectRgn(qd.thePort->clipRgn, gTempRgn, gTempRgn);
- if ((hDeltaOrg) || (vDeltaOrg))
- OffsetRgn(gTempRgn, hDeltaOrg, vDeltaOrg);
- SetClip(gTempRgn);
-
- #if qDebug
- DoneWithTempRgn();
- #endif
-
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- // Set clipping to: (<current clipping> INTERSECT r) OFFSET-BY (hDeltaOrg, vDeltaOrg)
- pascal void TView::OffsetAndClipFurtherTo(const Rect& r,
- short hDeltaOrg,
- short vDeltaOrg)
- {
- #if qDebug
- this->AssumeFocused();
- UseTempRgn("OffsetAndClipFurtherTo");
- #endif
-
- // First offset the clip Rgn
- if ((hDeltaOrg) || (vDeltaOrg))
- OffsetRgn(qd.thePort->clipRgn, hDeltaOrg, vDeltaOrg);
-
- // Now ClipFurtherTo
- RectRgn(gTempRgn, r);
- SectRgn(qd.thePort->clipRgn, gTempRgn, gTempRgn);
- SetClip(gTempRgn);
-
- #if qDebug
- DoneWithTempRgn();
- #endif
-
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- pascal void TView::Close(void)
- {
- // ??? Seems like we should notify the world that we're closing instead of groping around for
- // stuff like the last command…
- TCommand * lastCommand = this->GetLastCommand();
-
- if ((lastCommand) && (lastCommand->fView == this))
- this->CommitLastCommand();
-
- CSubViewIterator iter(this);
-
- for (TView * aView = iter.FirstSubView(); iter.More(); aView = iter.NextSubView())
- aView->Close();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::ComputeSize(VPoint& newSize)
- {
- VCoordinate dimension;
- VHSelect vhs;
- VPoint minSize;
-
- this->CalcMinSize(minSize);
-
- // Adjust view size based on size determiners.
- for (vhs = vSel; vhs <= hSel; ++vhs)
- {
- dimension = minSize[vhs]; // Set dimension to a default
- switch (fSizeDeterminer[vhs])
- {
- case sizeVariable: // For sizeVariable dimension is already set correctly
- break;
-
- case sizeFixed:
- dimension = fSize[vhs];
- break;
-
- case sizeRelSuperView:
- dimension = newSize[vhs]; // newSize set in SuperViewChangedSize
- break;
-
- case sizeSuperView:
- if (fSuperView)
- dimension = fSuperView->fSize[vhs];
- break;
-
- case sizePage:
- // If there is no printhandler we can defer until one is attached
- if (fPrintHandler)
- dimension = fPrintHandler->fViewPerPage[vhs];
- break;
-
- case sizeFillPages:
- // If there is no printhandler we can defer until one is attached
- if (fPrintHandler)
- dimension = Min(RoundUp(minSize[vhs], (short)(fPrintHandler->fViewPerPage[vhs])), kMaxCoord);
- break;
- }
- newSize[vhs] = dimension;
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Boolean TView::ContainsClipType(ResType aType)
- {
- long offset;
-
- return (GetScrap(NULL, aType, offset) > 0);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Boolean TView::ContainsMouse(const VPoint& theMouse)
- {
- VRect extent;
-
- this->GetExtent(extent);
- return (this->IsShown() && extent.Contains(theMouse));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal short TView::CountSubViews(void)
- {
- if (fSubViews)
- return fSubViews->GetSize();
- else
- return 0;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal VCoordinate TView::DoBreakFollowing(VHSelect vhs,
- VCoordinate prevBreak,
- Boolean& automatic)
- {
- return fPrintHandler->BreakFollowing(vhs, prevBreak, automatic);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::DoCalcPageStrips(VPoint& pageStrips)
- {
- fPrintHandler->CalcPageStrips(pageStrips);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::DoCalcViewPerPage(VPoint& viewPerPage)
- {
- viewPerPage = fSize; // in case fPrintHandler is vacuous
- fPrintHandler->CalcViewPerPage(viewPerPage);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::DoCheckPrinter(void)
- {
- fPrintHandler->CheckPrinter();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::DoDrawPrintFeedback(const VRect& area)
- {
- if (qDebug)
- this->AssumeFocused();
-
- if (fPrintHandler)
- fPrintHandler->DrawPrintFeedback(area);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::DoDrawPageBreak(VHSelect vhs,
- short whichBreak,
- VCoordinate loc,
- Boolean automatic)
- {
- fPrintHandler->DrawPageBreak(vhs, whichBreak, loc, automatic);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Boolean TView::HandlesCursor(void)
- {
- return (fHandlesCursor && this->IsEnabled()) || this->LetsSubViewsHandleCursor();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Boolean TView::LetsSubViewsHandleCursor(void)
- {
- return (fLetsSubViewsHandleCursor && fSubViews && (!fSubViews->IsEmpty()));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Boolean TView::HandlesHelp(void)
- {
- return fHandlesHelp || this->LetsSubViewsHandleHelp();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Boolean TView::LetsSubViewsHandleHelp(void)
- {
- return (fLetsSubViewsHandleHelp && fSubViews && (!fSubViews->IsEmpty()));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::DoHighlightSelection(HLState fromHL,
- HLState toHL)
- {
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- pascal void TView::DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* event,
- Point hysteresis)
- /* It's easy to get simple tracking that feeds back into your view. Just create a command!
- {
- TNoChangesCommand* aCommand;
- aCommand = new TNoChangesCommand;
- aCommand->INoChangesTracker(cNoCommand, fDocument, this, this->GetScroller(FALSE), theMouse);
- fTracksMouse = TRUE;
- this->PostCommand(aCommand);
- }
- */
-
- {
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::DoPagination(void)
- {
- if (fPrintHandler)
- fPrintHandler->RedoPageBreaks();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::DoPrinterChanged(void)
- {
- if (fPrintHandler)
- fPrintHandler->PrinterChanged();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAPrint
-
- pascal void TView::DoSetPageOffset(const VPoint& coord)
- {
- fPrintHandler->SetPageOffset(coord);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::DoSetCursor(const VPoint& localPoint,
- RgnHandle cursorRgn)
- {
- CursHandle aCursor;
-
- // Our default is to claim the cursor as an arrow for the default cursor region.
- if (qDebug)
- this->AssumeFocused();
-
- this->GetDefaultCursorRgn(localPoint, cursorRgn);
-
- if (fCursorID == kNoResource)
- SetCursor(qd.arrow);
- else
- {
- aCursor = GetCursor(fCursorID);
- FailNILResource((Handle)aCursor);
- SetCursor(**aCursor);
- }
-
- // If you claim the cursor don't forget to _PROPERLY_ calculate the cursorRgn or
- // WaitNextEvent might give you a lovely mouse-moved event shower. (Lather up!)
-
- // P.S. In debug this is checked for in our original caller: TApplication.TrackMouse.
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::DoShowBalloon(const VPoint& ,
- RgnHandle helpRgn,
- const HMMessageRecord& helpMessage,
- Point localQDTip,
- const Rect& localQDRect,
- short balloonVariant)
- {
- if (qNeedsHelpMgr || gConfiguration.hasHelpMgr)
- {
- Rect rect = localQDRect;
-
- LocalToGlobal(rect[topLeft]);
- LocalToGlobal(rect[botRight]);
- LocalToGlobal(localQDTip);
-
- OSErr err = (HMShowBalloon(helpMessage, localQDTip, NULL/**rect*/, NULL, 0, balloonVariant, kHMRegularWindow));
- if (err != hmBalloonAborted)
- FailOSErr(err);
-
- }
-
- // Intersect with visible region. Excludes the balloon region.
- SectRgn(qd.thePort->visRgn, helpRgn, helpRgn);
- SectRgn(qd.thePort->clipRgn, helpRgn, helpRgn);
-
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::DoShowHelp(const VPoint& localPoint,
- RgnHandle helpRgn)
- {
- HMMessageRecord helpMessage;
- Point tip;
- Rect hotRect;
- short balloonVariant;
-
- if ((qNeedsHelpMgr || gConfiguration.hasHelpMgr) && (fHelpID != kNoResource))
- {
- this->GetDefaultHelpRgn(localPoint, helpRgn);
- this->GetHelpParameters(localPoint, helpRgn, helpMessage, tip, hotRect, balloonVariant);
- this->DoShowBalloon(localPoint, helpRgn, helpMessage, tip, hotRect, balloonVariant);
- }
-
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::ExcludeSubViewRegions(RgnHandle aRegion,
- TestViewType TestSubView,
- void* staticLink)
- {
- const short kRgnHandleTooBig = 16 * 1024; // regions > 16K don't work too well, !!!
- // move this to the interfaces soon...
- Boolean rgnHandleWasTooBig;
-
- if (qDebug)
- this->AssumeFocused();
- #if qDebug
- UseTempRgn("ExcludeSubViewRegions");
- #endif
-
- rgnHandleWasTooBig = FALSE;
-
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- if (TestSubView(theSubView, staticLink) &&!rgnHandleWasTooBig)
- {
- VRect vFrame;
- Rect frame;
-
- theSubView->GetFrame(vFrame); // Remember, the frame is in OUR
- // coordinate system
- this->ViewToQDRect(vFrame, frame);
- RectRgn(gTempRgn, frame);
- DiffRgn(aRegion, gTempRgn, aRegion);// Remove the subview from the claimed rgn
-
- if ((GetHandleSize((Handle)aRegion) > kRgnHandleTooBig) || (MemError() != noErr))
- {
- rgnHandleWasTooBig = TRUE;
- SetEmptyRgn(aRegion);
- }
- }
-
- #if qDebug
- DoneWithTempRgn();
- #endif
-
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Boolean SubViewHandlesCursor(TView* aSubView,
- void*)
- {
- return aSubView->HandlesCursor() || aSubView->LetsSubViewsHandleCursor();
- }
-
-
- pascal void TView::GetDefaultCursorRgn(const VPoint&/* localPoint */ ,
- RgnHandle cursorRgn)
- {
- Rect r;
-
- /* If we get all the way to this view without any other view having claimed the
- cursor its because no superview handled it in a "HandleCursor" and no subview handled it
- in a "DoSetCursor" thus there is a _very_ high probability that this view should set the cursor.
- Just in case though, we remove the frames.
- If a containing view wishes to set the cursor for itself && all its subview, the
- place to do that is in our caller: HandleCursor. See HandleCursor in the homebrew controls
- TDialogView subclass in DemoDialogs.
- This strategy lets MacApp provide the _largest_ possible cursor rgn, as a default. This way
- windows, controls, background views, etc can have nice big cursor rgns but the developer can
- wrest control if they care to. */
-
- if (qDebug)
- this->AssumeFocused();
-
- this->GetQDExtent(r);
- RectRgn(cursorRgn, r);
-
- if (this->LetsSubViewsHandleCursor())
- this->ExcludeSubViewRegions(cursorRgn, SubViewHandlesCursor, this);/* We won't claim subviews'
- territory */
-
- // Intersect with visible region
- SectRgn(qd.thePort->visRgn, cursorRgn, cursorRgn);
- SectRgn(qd.thePort->clipRgn, cursorRgn, cursorRgn);
-
- // Add balloon region here? Re-intersect with visRgn?
-
- // Make sure the cursorpoint is _still_ included
- //!!! Done in TApplication.TrackCursor. PtAndRgn(this->ViewToQDPt(localPoint),cursorRgn);
-
- // If you claim the cursor don't forget to _PROPERLY_ calculate the cursorRgn or
- // WaitNextEvent might give you a lovely mouse-moved event shower. (Lather up!)
-
- // P.S. In debug this is checked for in our original caller: TApplication.TrackCursor.
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Boolean SubViewHandlesHelp(TView* aSubView,
- void*)
- {
- return aSubView->HandlesHelp();
- }
-
-
- pascal void TView::GetDefaultHelpRgn(const VPoint&/* localPoint */ ,
- RgnHandle helpRgn)
- {
- Rect r;
-
- if (qDebug)
- this->AssumeFocused();
-
- this->GetQDExtent(r);
- RectRgn(helpRgn, r);
-
- if (this->LetsSubViewsHandleHelp())
- this->ExcludeSubViewRegions(helpRgn, SubViewHandlesHelp, this);// We won't claim subviews' territory
-
- // Make sure the cursorpoint is _still_ included
- //!!! Done in TApplication.TrackHelp. PtAndRgn(this->ViewToQDPt(localPoint),helpRgn);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::GetLocalOffsetInSuper(VPoint& localOffsetInSuper)
- {
- localOffsetInSuper = fLocation - fTranslation;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::SetLocalOrigin(const VPoint& newOrigin,
- Boolean redraw)
- {
- fTranslation = -newOrigin;
- this->InvalidateFocus();
- this->UpdateCoordinates();
- if (redraw)
- this->ForceRedraw();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal TDesignator* TView::GetUserSelection(void)
- {
- if (fDocument)
- return fDocument->GetUserSelection();
- else
- return NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::SetUserSelection(TDesignator* newSelection)
- {
- if (fDocument)
- fDocument->SetUserSelection(newSelection);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::UserSelectionChanged(void)
- {
- if (fDocument)
- fDocument->UserSelectionChanged();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::Draw(const VRect& area)
- {
- // You should really try to call inherited draw to be ready for the future.
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::DrawContents(void)
- {
- if (!fVisibleExtent.Empty() && this->IsShown() && this->Focus())
- {
- // Even if the fVisibleExtent is not empty the Drawable rect might be
- VRect visRect;
-
- this->GetDrawableRect(visRect);
- if (!visRect.Empty())
- {
- if (fViewAdornment)
- fViewAdornment->DrawContents(this, visRect);
- else
- this->Draw(visRect);
-
- // Give the beahvior a chance to draw
- TViewBehavior * aBehavior = (TViewBehavior *)this->GetFirstBehavior();
- if (aBehavior)
- aBehavior->Draw(visRect);
-
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- theSubView->DrawContents();
-
- // now add the adornments
- if (!(gPrinting || gDrawingPictScrap) && fViewAdornment)
- fViewAdornment->DoHighlightSelection(this, visRect, hlOff, fHLDesired);
- }
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::EachSubView(pascal void(* DoToSubView)(TView* theSubView,
- void* staticLink),
- void* staticLink)
- {
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- (*DoToSubView)(theSubView,staticLink);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal TView* TView::FindSubView(IDType itsIdentifier)
- {
- if (((long)fIdentifier) == ((long)itsIdentifier))
- return this;
- else
- {
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- if (((long)theSubView->fIdentifier) == ((long)itsIdentifier))
- return theSubView;
- else if (theSubView->fSubViews)
- {
- TView * foundSubView = theSubView->FindSubView(itsIdentifier);
- if (foundSubView)
- return foundSubView;
- }
- return NULL;
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal TView* TView::FirstSubViewThat(pascal Boolean(* TestSubView)(TView* theSubView,
- void* staticLink),
- void* staticLink)
- {
- if (fSubViews)
- return ((TView *)fSubViews->FirstThat((TestObjectType)TestSubView, staticLink));
- else
- return NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Boolean TView::Focus(void)
- {
- #if qDebug
- GrafPtr currentPort;
- #endif
-
- if (this->IsFocused()) // Already focused
- {
- #if qDebug
- GetPort(currentPort);
- if (this->GetGrafPort() != currentPort)
- ProgramBreak("TView.Focus: Port is incorrect");
- #endif
-
- }
- else if (this->FocusOnSuperView()) // do my own focus
- {
- Point relOrigin;
-
- SetOrigin(fQDOrigin.h, fQDOrigin.v); // set the new QD origin
- if (fSuperView)
- relOrigin = fQDOrigin - fSuperView->fQDOrigin;// extract the relorigin
- else
- relOrigin = gZeroPt;
-
- gFocusedView = this; // Now we have the basic focus
-
- // Add the clipping
- Rect visQDRect;
-
- this->GetVisibleQDRect(visQDRect);
- this->OffsetAndClipFurtherTo(visQDRect, relOrigin.h, relOrigin.v);
- }
- else // Can't focus
- return FALSE;
- return TRUE;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Boolean TView::FocusOnSuperView(void)
- {
- if (gDrawingPictScrap || gPrinting)
- return TRUE;
- else if (fSuperView)
- return fSuperView->Focus();
- else
- return FALSE;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::ForceRedraw(void)
- {
- if (this->IsVisible())
- {
- VRect extent;
-
- this->GetExtent(extent);
- this->InvalidateVRect(extent);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAClipboard
-
- pascal void TView::FreeFromClipboard(void)
- {
- if (fDocument)
- fDocument->FreeFromClipboard();
- else
- this->Free();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAInspector
-
- pascal void TView::GetInspectorName(Str255& inspectorName)// override
- {
- TView * itsRootView = this->GetRootView();
-
- if ((itsRootView) && itsRootView->IsMemberClass(GetClassIDFromName("TWindow")))
- {
- ((TWindow *)itsRootView)->GetTitle(inspectorName);
- inspectorName = "In " + inspectorName;
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Boolean TView::IsFocused(void)
- {
- if (gFocusedView == this)
- return TRUE;
- else if ((gDrawingPictScrapView == this) || ((gCurrPrintHandler) && (gCurrPrintHandler->fView == this)))// externally supplied focus
- {
- gFocusedView = this;
- return TRUE;
- }
- else
- return FALSE;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal TView* TView::GetDialogView(void)
- {
- if (fSuperView)
- return fSuperView->GetDialogView();
- else
- return NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::GetExtent(VRect& itsExtent)
- {
- VPoint localOriginInSuper;
-
- itsExtent = VRect(gZeroVPt, fSize);
-
- // Allow for the origin of the view's coordinate system.
- this->GetLocalOffsetInSuper(localOriginInSuper);
- localOriginInSuper -= fLocation;
- itsExtent -= localOriginInSuper;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::GetFrame(VRect& itsFrame)
- {
- itsFrame = VRect(fLocation, fLocation + fSize);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal GrafPtr TView::GetGrafPort(void)
- {
- if (gPrinting || gDrawingPictScrap)
- return qd.thePort; //thePort assumed to be set by print handler
- else if (fSuperView)
- return fSuperView->GetGrafPort();
- else
- return NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal short TView::GetPartCode(const VPoint& theMouse)
- {
- VRect extent;
-
- this->GetExtent(extent);
- if (extent.Contains(theMouse))
- return inContent; // "where" is in the view
- else
- return inDesk; // "where" isn't in the view
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::GetPrintExtent(VRect& printExtent)
- {
- this->GetExtent(printExtent);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::GetQDExtent(Rect& qdExtent)
- {
- VRect vr;
-
- this->GetExtent(vr);
- this->ViewToQDRect(vr, qdExtent);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal TScroller* TView::GetScroller(Boolean immediateSuperView)
- {
- TScroller * aScroller;
-
- if (fSuperView)
- {
- aScroller = fSuperView->GetScroller(immediateSuperView);
- if ((aScroller == fSuperView) || (!immediateSuperView))
- return aScroller;
- }
- return NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::GetVisibleRect(VRect& visRect)
- {
- Rect visQDRect;
-
- this->GetVisibleQDRect(visQDRect);
- this->QDToViewRect(visQDRect, visRect);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::GetVisibleQDRect(Rect& visQDRect)
- {
- if (!fVisibleExtent.Empty())
- {
- this->ViewToQDRect(fVisibleExtent, visQDRect);
- VisibleRect(visQDRect);
- }
- else
- visQDRect = gZeroRect;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::GetDrawableRect(VRect& drawRect)
- {
- Rect drawQDRect;
-
- this->GetDrawableQDRect(drawQDRect);
- this->QDToViewRect(drawQDRect, drawRect);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::GetDrawableQDRect(Rect& drawQDRect)
- {
- this->GetVisibleQDRect(drawQDRect);
- if (!drawQDRect.Empty())
- DrawableRect(drawQDRect);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::GetHelpParameters(const VPoint& localPoint,
- RgnHandle helpRgn,
- HMMessageRecord& helpMessage,
- Point& localQDTip,
- Rect& localQDRect,
- short& balloonVariant)
- {
- long options;
- short theProc;
- short count;
-
- //!!! Error checking?
- FailOSErr(HMGetIndHelpMsg(kHMRectListResType, fHelpID, 1,// component number within resource
- kHMEnabledItem, options, localQDTip, localQDRect, theProc, balloonVariant, helpMessage, count));
-
- // Ignore the hotRect from the resource
- if (helpRgn)
- {
- localQDRect = (*helpRgn)->rgnBBox;
- if ((localQDTip.h < 0) || (localQDTip.v < 0))
- {
- localQDTip = this->ViewToQDPt(localPoint);
- }
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal TView* TView::GetRootView(void)
- {
- if (fSuperView)
- return fSuperView->GetRootView();
- else
- return this;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal TWindow* TView::GetWindow(void)
- {
- TView * rootView = this->GetRootView();
-
- if ((rootView) && rootView->IsMemberClass(GetClassIDFromName("TWindow")))
- return (TWindow *)rootView;
- else
- return NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAClipboard
-
- pascal long TView::GivePasteData(Handle aDataHandle,
- ResType dataType)
- {
- long offset;
- long err;
- Boolean savedPerm;
-
- // Make sure the scrap handle is grown out of permanent memory. If it
- // was grown out of temporary memory it would eat away at our code space.
- savedPerm = PermAllocation(TRUE);
- err = GetScrap(aDataHandle, dataType, offset);
- savedPerm = PermAllocation(savedPerm);
-
- #if qDebugMsg
- if (err < 0)
- fprintf(stderr, "TView.GivePasteData got error code # %d from GetScrap for type %s\n", err, (char*) & dataType);
- #endif
-
- return err;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal TView* TView::HandleCursor(const VPoint& theMouse,
- RgnHandle cursorRgn)
- {
- TView * viewThatHandledCursor = NULL;
-
- //Assume if we got here then we already know the mouse is in this view
- if (this->LetsSubViewsHandleCursor())
- {
- CSubViewIterator iter(this, kIterateBackward);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- {
- VPoint subViewPt = theMouse;
-
- theSubView->SuperToLocal(subViewPt);
- if ((theSubView->ContainsMouse(subViewPt) && theSubView->HandlesCursor()))
- if (viewThatHandledCursor = theSubView->HandleCursor(subViewPt, cursorRgn))
- break;
- }
- }
-
- if (!viewThatHandledCursor && this->Focus())
- {
- // First let the Behavior have a crack at handling the cursor
- Boolean proceed = true;
-
- if (this->GetFirstBehavior())
- proceed =!((TViewBehavior *)this->GetFirstBehavior())->DoSetCursor(theMouse, cursorRgn);
-
- if (proceed)
- this->DoSetCursor(theMouse, cursorRgn);
-
- viewThatHandledCursor = this;
- }
-
- return viewThatHandledCursor;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal TView* TView::HandleHelp(const VPoint& theMouse,
- RgnHandle helpRgn)
- {
- //Assume if we got here then we already know the mouse is in this view
-
- TView * viewThatShowedHelp = NULL;
-
- CSubViewIterator iter(this, kIterateBackward);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- {
- VPoint subViewPt = theMouse;
-
- theSubView->SuperToLocal(subViewPt);
-
- if (theSubView->ContainsMouse(subViewPt) && theSubView->HandlesHelp())
- if (viewThatShowedHelp = theSubView->HandleHelp(subViewPt, helpRgn))
- break;
- }
-
- if (!viewThatShowedHelp && this->HandlesHelp() && this->Focus())
- {
- this->DoShowHelp(theMouse, helpRgn);
- viewThatShowedHelp = this;
- }
-
- return viewThatShowedHelp;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- pascal Boolean TView::HandleMouseDown(const VPoint& theMouse,
- TToolboxEvent* event,
- Point hysteresis)
- {
-
- // Assume if we got here then we already know the mouse is in this view
- // If desired, we set the target BEFORE traversing the subviews, because
- // setting the target may alter the view hierarchy, as in the case of
- // TEditTexts, which install a "floating" TEView
-
- if (this->IsEnabled() && this->WantToBecomeTarget())
- this->BeTarget();
-
- CSubViewIterator iter(this, kIterateBackward);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- {
- VPoint subViewPt = theMouse;
-
- theSubView->SuperToLocal(subViewPt);
- if (theSubView->ContainsMouse(subViewPt))
- if (theSubView->HandleMouseDown(subViewPt, event, hysteresis))
- return TRUE;
- }
-
- if (this->IsEnabled() && this->Focus()) // see if we can handle it
- {
- Point globalMouse;
- VPoint tempMouse = theMouse; // We do this so we can pass a const to DoMouseCommand
-
- if (gApplication->IsCursorRgnInvalid()) // This is important to allowing the cursor
- // to change when selecting
- {
- globalMouse = this->ViewToQDPt(theMouse);
- LocalToGlobal(globalMouse);
- gApplication->TrackCursor(globalMouse);
- this->Focus();
- }
-
- // Change added to support ViewBehaviors
- Boolean proceed = true;
-
- if (this->GetFirstBehavior())
- proceed =!((TViewBehavior *)this->GetFirstBehavior())->DoMouseCommand(tempMouse, event, hysteresis);
-
- if (proceed)
- this->DoMouseCommand(tempMouse, event, hysteresis);
-
- return TRUE;
- }
- else
- return FALSE;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Boolean TView::HasPendingUpdate(void)
- {
- if (fSuperView)
- return fSuperView->HasPendingUpdate();
- else
- return FALSE;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::InvalidateVRect(const VRect& badVRect)
- {
- Rect r;
-
- this->ViewToQDRect(badVRect, r);
- this->InvalidateRect(r);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::InvalidateRect(const Rect& badRect)
- {
- RgnHandle rgn = NewRgn(); // Believe it or not, QD does this on an invalRect call!
- RectRgn(rgn, badRect);
- this->InvalidateRgn(rgn);
- rgn = DisposeIfRgnHandle(rgn);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::InvalidateRgn(RgnHandle badRgn)
- {
- if (this->Focus())
- {
- Rect r;
-
- this->ViewToQDRect(fVisibleExtent, r);
- #if qDebug
- UseTempRgn("TView.InvalidateRgn");
- #endif
-
- RectRgn(gTempRgn, r);
- SectRgn(badRgn, gTempRgn, gTempRgn);
- if (!EmptyRgn(gTempRgn))
- this->DoInvalidateRgn(gTempRgn);
- #if qDebug
- DoneWithTempRgn();
- #endif
-
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::DoInvalidateRgn(RgnHandle badRgn)
- {
- if (fSuperView)
- fSuperView->DoInvalidateRgn(badRgn); // see if someone knows how
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::InvalidateFocus(void)
- {
- gFocusedView = NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Boolean TView::IsShown(void)
- {
- // By definition a view can't be shown if its superview isn't shown
- if (fSuperView)
- return (fShown && fSuperView->IsShown());
- else
- return fShown;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Boolean TView::IsActive(void)
- {
- if (fSuperView)
- return fSuperView->IsActive();
- else
- return FALSE; // Can't be "active" without a superview
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Boolean TView::IsDrawable(void)
- {
-
- if (this->IsShown() && this->Focus()) // leaves view focused if it is drawable
- {
- Rect r;
-
- this->GetDrawableQDRect(r);
- return !r.Empty();
- }
- else
- return FALSE;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Boolean TView::IsVisible(void)
- {
- if (this->IsShown())
- {
- Rect r;
-
- this->GetVisibleQDRect(r);
- return !r.Empty();
- }
- else
- return FALSE;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal TView* TView::LastSubViewThat(pascal Boolean(* TestSubView)(TView* theSubView,
- void* staticLink),
- void* staticLink)
- {
- if (fSubViews)
- return (TView *)(fSubViews->LastThat((TestObjectType)TestSubView, staticLink));
- else
- return NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::LocalToSuper(VPoint& thePoint)
- {
- VPoint localOriginInSuper;
-
- this->GetLocalOffsetInSuper(localOriginInSuper);
- thePoint += localOriginInSuper;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::LocalToSuperVRect(VRect& viewRect)
- {
- this->LocalToSuper(viewRect[topLeft]);
- this->LocalToSuper(viewRect[botRight]);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::LocalToSuperRgn(RgnHandle& theRgn)
- {
- VPoint localVOriginInSuper;
-
- this->GetLocalOffsetInSuper(localVOriginInSuper);
- Point localOriginInSuper = localVOriginInSuper;// don't want to require focusing
- OffsetRgn(theRgn, localOriginInSuper.h, localOriginInSuper.v);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::LocalToWindow(VPoint& thePoint)
- {
- if (fSuperView)
- {
- this->LocalToSuper(thePoint);
- fSuperView->LocalToWindow(thePoint);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::Locate(const VPoint& newLoc,
- Boolean invalidate)
- {
- if (newLoc != fLocation)
- {
-
- if (invalidate)
- this->ForceRedraw();
- fLocation = newLoc;
- this->InvalidateFocus(); // Must re-focus because view moved.
- this->UpdateCoordinates();
- gApplication->InvalidateMouseRegions(); // Must re-calc cursor and help regions.
- if (invalidate)
- this->ForceRedraw();
-
- if (fSuperView)
- fSuperView->SubViewMoved(this);
-
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- theSubView->SuperViewMoved(invalidate);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::MakeFirstSubView(TView* theSubView)
- {
- if (fSubViews) //there must be at least one subview
- if (((TView *)fSubViews->First()) != theSubView)
- {
- fSubViews->Delete(theSubView);
- fSubViews->InsertFirst(theSubView);
- theSubView->ForceRedraw();
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::MakeLastSubView(TView* theSubView)
- {
- if (fSubViews) //there must be at least one subview
- if (((TView *)fSubViews->Last()) != theSubView)
- {
- fSubViews->Delete(theSubView);
- fSubViews->InsertLast(theSubView);
- theSubView->ForceRedraw();
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal void TView::Open(void)
- {
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- theSubView->Open();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::PageInteriorChanged(const VRect& newInterior)
- {
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::QDToViewPt(Point qdPoint,
- VPoint& viewPt)
- {
- viewPt = VPoint(qdPoint) + fViewToQDOffset;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::QDToViewRect(const Rect& qdRect,
- VRect& viewRect)
- {
- viewRect = qdRect + fViewToQDOffset;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::RemovedASubView(TView* theSubView)
- {
- if (fSuperView)
- fSuperView->RemovedASubView(theSubView);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::RemoveSubView(TView* theSubView)
- {
- if (qDebug)
- FailNonObject(theSubView);
-
- if (fSubViews)
- {
- fSubViews->Delete(theSubView);
-
- // If there aren't any subviews left we free the list
- if (fSubViews->IsEmpty())
- fSubViews = (TList *)FreeIfObject(fSubViews);
- }
-
- this->RemovedASubView(theSubView);
- theSubView->BeInSuperView(NULL);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::Resize(const VPoint& newSize,
- Boolean invalidate)
- {
- if (newSize != fSize)
- {
- VPoint delta;
- VRect oldFrame;
- VRect newFrame;
- VRect badVRect;
-
- if (invalidate)
- this->GetFrame(oldFrame);
-
-
- delta = newSize - fSize;
- fSize = newSize;
-
- this->InvalidateFocus(); // Must re-focus because size changed
- this->UpdateCoordinates();
- gApplication->InvalidateMouseRegions(); // Must re-calc cursor and help regions
-
- if (invalidate)
- {
- this->GetFrame(newFrame);
-
- if (this->FocusOnSuperView())
- {
- if (oldFrame.right != newFrame.right)// must invalidate width difference
- {
- badVRect = VRect(Min(oldFrame.top, newFrame.top), Min(oldFrame.right, newFrame.right),
- Max(oldFrame.bottom, newFrame.bottom), Max(oldFrame.right, newFrame.right));
- if (fSuperView)
- fSuperView->InvalidateVRect(badVRect);
- }
-
- if (oldFrame.bottom != newFrame.bottom)// must invalidate height difference
- {
- badVRect = VRect(Min(oldFrame.bottom, newFrame.bottom), Min(oldFrame.left, newFrame.left),
- Max(oldFrame.bottom, newFrame.bottom), Max(oldFrame.right, newFrame.right));
- if (fSuperView)
- fSuperView->InvalidateVRect(badVRect);
- }
- }
- }
-
- if (fSuperView)
- fSuperView->SubViewChangedSize(this, delta);
-
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- {
- // • Let any adorners no that the view might be changing size
- if ( theSubView->fViewAdornment )
- theSubView->fViewAdornment->ViewChangedSize ( this, delta, invalidate );
-
- theSubView->SuperViewChangedSize(delta, invalidate);
- }
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAScroll
-
- pascal void TView::RevealBottom(Boolean redraw)
- {
- this->RevealRect(VRect(fSize, fSize), gZeroVPt, redraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAScroll
-
- pascal void TView::RevealRect(const VRect& rectToReveal,
- const VPoint& minToSee,
- Boolean redraw)
- {
- if (fSuperView)
- {
- VRect localRectToReveal(rectToReveal);
-
- this->LocalToSuperVRect(localRectToReveal);
- fSuperView->RevealRect(localRectToReveal, minToSee, redraw);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAScroll
-
- pascal void TView::RevealTop(Boolean redraw)
- {
- this->RevealRect(gZeroVRect, gZeroVPt, redraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::SetTarget(TEvtHandler* newTarget)
- {
- if (fSuperView)
- fSuperView->SetTarget(newTarget);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::Show(Boolean state,
- Boolean redraw)
- {
- if (state != fShown)
- {
- if (redraw)
- {
- fShown = TRUE; // So that ForceRedraw works.
- this->ForceRedraw();
- }
- this->InvalidateFocus();
- gApplication->InvalidateMouseRegions(); // Must re-calc cursor and help regions
- fShown = state;
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAReadFile
-
- pascal void TView::ShowReverted(void)
- {
- this->AdjustSize();
- this->ForceRedraw();
-
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- theSubView->ShowReverted();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::SubViewChangedSize(TView* theSubView,
- const VPoint& delta)
- {
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::SubViewMoved(TView* theSubView)
- {
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::SuperToLocal(VPoint& thePoint)
- {
- VPoint localOriginInSuper;
-
- this->GetLocalOffsetInSuper(localOriginInSuper);
- thePoint -= localOriginInSuper;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::SuperToLocalVRect(VRect& viewRect)
- {
- this->SuperToLocal(viewRect[topLeft]);
- this->SuperToLocal(viewRect[botRight]);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::SuperToLocalRgn(RgnHandle& theRgn)
- {
- VPoint localVOriginInSuper;
-
- this->GetLocalOffsetInSuper(localVOriginInSuper);
- Point localOriginInSuper = localVOriginInSuper;// don't want to require focusing
- OffsetRgn(theRgn, -localOriginInSuper.h, -localOriginInSuper.v);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::SuperViewChangedSize(const VPoint& delta,
- Boolean invalidate)
- {
- VPoint newSize = fSize;
- Boolean needsResizing = FALSE;
-
- for (VHSelect vhs = vSel; vhs <= hSel; ++vhs)
- {
- if (fSizeDeterminer[vhs] == sizeSuperView)
- needsResizing = TRUE;
- else if (fSizeDeterminer[vhs] == sizeRelSuperView)
- {
- newSize[vhs] = newSize[vhs] + delta[vhs];
- needsResizing = TRUE;
- }
- }
-
- if (needsResizing)
- {
- this->ComputeSize(newSize);
- this->Resize(newSize, invalidate);
- this->DoPagination();
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::SuperViewMoved(Boolean invalidate)
- {
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- pascal Boolean TView::IsDoneTracking(void)
- {
- // Default to mouse-down tracking
- return !StillDown();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- pascal void TView::TrackConstrain(TrackPhase aTrackPhase,
- const VPoint& anchorPoint,
- const VPoint& previousPoint,
- VPoint& nextPoint,
- Boolean mouseDidMove)
- {
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- pascal void TView::TrackFeedback(TrackPhase /* aTrackPhase */,
- const VPoint& anchorPoint,
- const VPoint& /* previousPoint */,
- const VPoint& nextPoint,
- Boolean mouseDidMove,
- Boolean /* turnItOn */)
-
- // Use code like this to get a flickering rectangle.
- {
- if (mouseDidMove)
- {
- Rect r;
- VRect vr(anchorPoint, nextPoint);
-
- this->ViewToQDRect(vr, r);
- PenPat(qd.gray);
- FrameRect(r);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- pascal void TView::TrackMouse(TrackPhase aTrackPhase,
- VPoint& anchorPoint,
- VPoint& previousPoint,
- VPoint& nextPoint,
- Boolean mouseDidMove)
- {
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::TraverseSubViewsPreOrder(DoToViewType DoToSubView,
- void* staticLink)
- {
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- {
- DoToSubView(theSubView, staticLink);
- theSubView->TraverseSubViewsPreOrder(DoToSubView, staticLink);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::TraverseSubViewsPostOrder(DoToViewType DoToSubView,
- void* staticLink)
- {
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- {
- theSubView->TraverseSubViewsPostOrder(DoToSubView, staticLink);
- DoToSubView(theSubView, staticLink);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::Update(void)
- {
- if (fSuperView)
- fSuperView->Update();
- else
- this->DrawContents();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::ValidateVRect(const VRect& goodVRect)
- {
- Rect r;
-
- this->ViewToQDRect(goodVRect, r);
- this->ValidateRect(r);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::ValidateRect(const Rect& goodRect)
- {
- RgnHandle rgn = NewRgn(); // Believe it or not, QD does this on an invalRect call!
-
- RectRgn(rgn, goodRect);
- this->ValidateRgn(rgn);
- rgn = DisposeIfRgnHandle(rgn);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::ValidateRgn(RgnHandle goodRgn)
- {
- Rect r;
-
- if (this->Focus())
- {
- this->ViewToQDRect(fVisibleExtent, r);
-
- #if qDebug
- UseTempRgn("TView.ValidateRgn");
- #endif
-
- RectRgn(gTempRgn, r);
- SectRgn(goodRgn, gTempRgn, gTempRgn);
- if (!EmptyRgn(gTempRgn))
- this->DoValidateRgn(gTempRgn);
- #if qDebug
- DoneWithTempRgn();
- #endif
-
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::DoValidateRgn(RgnHandle goodRgn)
- {
- if (fSuperView)
- fSuperView->DoValidateRgn(goodRgn); // see if someone knows how
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::ViewEnable(Boolean state,
- Boolean redraw)
- {
- this->SetEnable(state);
-
- if (redraw)
- this->ForceRedraw();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal Point TView::ViewToQDPt(const VPoint& viewPt)
- {
- return viewPt - fViewToQDOffset;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::ViewToQDRect(const VRect& viewRect,
- Rect& qdRect)
- {
- qdRect = viewRect - fViewToQDOffset;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::WindowToLocal(VPoint& thePoint)
- {
- if (fSuperView)
- {
- fSuperView->WindowToLocal(thePoint);
- this->SuperToLocal(thePoint);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal PicHandle TView::AsPict(void)
- {
- PicHandle pHndl = NULL;
- Boolean pictureIsOpen;
- Rect qdExtent;
- GrafPort tempPort;
- CGrafPort tempCPort;
- FailInfo fi;
-
- VOLATILE(pHndl);
- VOLATILE(pictureIsOpen);
-
- this->InvalidateFocus();
-
- gDrawingPictScrap = TRUE;
- gDrawingPictScrapView = this;
- if (qNeedsColorQD || gConfiguration.hasColorQD)
- {
- OpenCPort(&tempCPort);
- this->BeInPort((GrafPort *) & tempCPort);
- }
- else
- {
- OpenPort(&tempPort);
- this->BeInPort(&tempPort);
- }
- //??? how do we catch openport failures?
-
- if (fi.Try())
- {
- if (this->Focus())
- {
- //Open color or black && white, depending on the port
- this->GetQDExtent(qdExtent);
- pHndl = OpenPicture(qdExtent);
- pictureIsOpen = TRUE; // Failure handler needs to close it
- FailNIL(pHndl);
-
- ClipRect(qdExtent);
- this->DrawContents();
- ClosePicture();
- pictureIsOpen = FALSE; // Failure handler doesn't need to close it
-
- // On the 128K ROMs the picFrame will be empty if drawing the
- // picture failed. On the 64K ROM's QuickDraw simply bombs.
- if ((*pHndl)->picFrame.Empty())
- {
- if (qDebug)
- fprintf(stderr, "Picture frame is empty!\n");
- FailOSErr(memFullErr);
- }
-
- this->InvalidateFocus();
- }
- else if (qDebug) // can't focus
- ProgramBreak("Can't focus view while writing picture to desk scrap");
-
- fi.Success();
- }
- else // Recover
- {
- if (pHndl)
- {
- if (pictureIsOpen)
- ClosePicture();
- KillPicture(pHndl);
- pHndl = NULL;
- }
-
- if (qNeedsColorQD || gConfiguration.hasColorQD)
- CloseCPort(&tempCPort);
- else
- ClosePort(&tempPort);
- SetPort(gWorkPort);
- this->BeInPort(NULL);
- gDrawingPictScrap = FALSE;
- gDrawingPictScrapView = NULL;
- fi.ReSignal();
- }
- if (qNeedsColorQD || gConfiguration.hasColorQD)
- CloseCPort(&tempCPort);
- else
- ClosePort(&tempPort);
- SetPort(gWorkPort);
- gDrawingPictScrap = FALSE;
- gDrawingPictScrapView = NULL;
- this->BeInPort(NULL);
-
- return pHndl;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::WriteToDeskScrap(void)
- {
- PicHandle pHndl = NULL;
- FailInfo fi;
-
- VOLATILE(pHndl);
-
- if (fi.Try())
- {
- pHndl = this->AsPict();
- FailNIL(pHndl);
-
- FailOSErr(gClipboardMgr->PutDeskScrapData('PICT', (Handle)pHndl));
-
- KillPicture(pHndl); // dispose of picture created by AsPict
- pHndl = NULL; // So failure handler doesn't to kill it
- fi.Success();
- }
- else // Recover
- {
- if (pHndl)
- {
- if (qDebug)
- ProgramBreak("Failed to put PICT-type scrap");
- KillPicture(pHndl);
- }
- pHndl = NULL;
- fi.ReSignal();
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::GoAwayByUser(const VPoint& theMouse)
- {
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::MoveByUser(const VPoint& theMouse)
- {
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::ResizeByUser(const VPoint& theMouse)
- {
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::SetHLPenState(HLState fromHL,
- HLState toHL)
- {
- PatPtr pPat;
- short mode = patXor; // every transition except hlOn <-> hlDim uses patXOR
-
- if (fromHL + toHL == hlOffOn)
- pPat = qd.black;
-
- else if (fromHL != toHL)
- pPat = qd.gray; // ??? make this pattern a parameter ???
-
- if (fromHL + toHL == hlDimOn)
- mode = notPatXor;
-
- PenMode(mode);
- PenPat(pPat);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- pascal void TView::UpdateCoordinates(void)
- {
-
- const short kMaxOriginFixup = 1024; /* The maximum amout by which to _fixup_ (not
- offset) the QD origin when focusing. This
- allows patterns and pixpats to be pinned
- to global space as they were intended. See
- note below. Larger values than this may be
- required for _extremely_ complex pixpats
- (not patterns as they are restricted to 8
- bit repetition.) The reason that the fixup
- is restricted is that you don't want to
- run off the end of QD space and we already
- have slop allowance of about 2k in
- ViewCoords.p. (??? should this be settable
- for the adventurous?) */
-
-
- /* First calculate and setup the new origins.
- But first a word about this approach. (thanks kaar!)
- Problems with pattern alignment when using 32bit views occur when virtual
- origin of the port has coordinates that are not multiples of 8. This
- can occur if, for example, you scroll a view by increments of other than 8,
- 16, or other multiple of 8.
- The solution is to appropriately set the origin so that patterns are drawn
- correctly aligned. This can be done by making sure that we set the origin to
- some value that will cause QuickDraw to perform in exactly the same way as if
- the origin were really at the value specified by fViewToQDOffset. Since classic
- QuickDraw patterns repeat after 8 pixels, we can accomplish this task by making
- sure that fViewToQDOffset is a multiple of 8, and setting the origin to compensate
- by setting it to fViewToQDOffset % 8.
- Unfortunately, this will only work for classic QuickDraw patterns that repeat
- after 8 pixels. With PixPats, this period can be any power of 2. In order to
- support them, we have to make sure that fViewToQDOffset must be only a multiple of
- whatever power of 2 is being used. Ideally, therefore, we could like to make
- the chunkiness of fViewToQDOffset to be as large as possible. On the other hand, we
- can make it too large, or else the amount by which we offset the origin in
- TView.Focus may overflow QuickDraw's limits. Probably a value of 1024 or
- 2048 should be sufficient enough to accomodate the largest of PixPats a
- developer may use, and still be small enough that we shouldn't overflow
- QuickDraw.
- */
- if (fSuperView)
- {
- VPoint localOriginInSuper;
- this->GetLocalOffsetInSuper(localOriginInSuper);
- VPoint actualViewToQDOffset = fSuperView->fViewToQDOffset - localOriginInSuper;
-
- Point deltaOrigin = actualViewToQDOffset;
- if (fSize > VPoint(kMaxCoord, kMaxCoord))
- deltaOrigin = Point((short)(deltaOrigin.v % kMaxOriginFixup), (short)(deltaOrigin.h % kMaxOriginFixup));
- fQDOrigin = fSuperView->fQDOrigin + deltaOrigin;
- fViewToQDOffset = actualViewToQDOffset - VPoint(deltaOrigin);
-
- // Update my visible extent by intersecting my extent with my superview's visible extent
-
- // When printing, or drawing the scrap, the grafPort is supplied.
- if ((gDrawingPictScrapView == this) || ((gCurrPrintHandler != NULL) && (gCurrPrintHandler->fView == this)))
- {
- VRect itsExtent;
- this->GetExtent(itsExtent);
- fVisibleExtent = itsExtent;
- }
- else
- {
- VRect itsFrame;
- this->GetFrame(itsFrame);
- fVisibleExtent = itsFrame & fSuperView->fVisibleExtent;
- this->SuperToLocalVRect(fVisibleExtent);
- }
- }
- else
- {
- VRect itsExtent;
-
- fViewToQDOffset = gZeroVPt;
- fQDOrigin = gZeroPt;
- this->GetExtent(itsExtent);
- fVisibleExtent = itsExtent;
- }
-
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- theSubView->UpdateCoordinates();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- pascal void TView::ZoomByUser(const VPoint& theMouse,
- short partCode)
- {
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFields
-
- pascal void TView::Fields(TObject* obj) // override
- {
- obj->DoToField("TView", (Ptr)NULL, bClass);
- obj->DoToField("fSuperView", (Ptr) & fSuperView, bObject);
- obj->DoToField("fSubViews", (Ptr) & fSubViews, bObject);
- obj->DoToField("fDocument", (Ptr) & fDocument, bObject);
- obj->DoToField("fLocation", (Ptr) & fLocation, bVPoint);
- obj->DoToField("fSize", (Ptr) & fSize, bVPoint);
- obj->DoToField("fTranslation", (Ptr) & fTranslation, bVPoint);
- obj->DoToField("fSizeDeterminer[hSel]", &fSizeDeterminer[hSel], bSizeDeterminer);
- obj->DoToField("fSizeDeterminer[vSel]", &fSizeDeterminer[vSel], bSizeDeterminer);
- obj->DoToField("fHLDesired", (Ptr) & fHLDesired, bHLState);
- obj->DoToField("fShown", (Ptr) & fShown, bBoolean);
- obj->DoToField("fPrintHandler", (Ptr) & fPrintHandler, bObject);
-
- obj->DoToField("fViewToQDOffset", (Ptr) & fViewToQDOffset, bVPoint);
- obj->DoToField("fQDOrigin", (Ptr) & fQDOrigin, bPoint);
- obj->DoToField("fVisibleExtent", (Ptr) & fVisibleExtent, bVRect);
-
- obj->DoToField("fHandlesCursor", (Ptr) & fHandlesCursor, bBoolean);
- obj->DoToField("fSubViewsHandleCursor", (Ptr) & fShown, bBoolean);
- obj->DoToField("fHandlesHelp", (Ptr) & fShown, bBoolean);
- obj->DoToField("fSubViewsHandleHelp", (Ptr) & fShown, bBoolean);
-
- inherited::Fields(obj);
- }
-
-
-